package org.ns.summer.data.mybatis;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Result {
    // 失败的数据源
    private Set<String> failDataSources = new HashSet<>();

    public void addFailDataSource(String dataSourceName) {
        failDataSources.add(dataSourceName);
    }
    public void addFailDataSources(Collection<String> dataSourceNames) {
        failDataSources.addAll(dataSourceNames);
    }
    public boolean commitOk() {
        return failDataSources.size() == 0;
    }

    public void throwFailException() {
        if (!commitOk()) {
            throw new RuntimeException("提交失败: " + failDataSources);
        }
    }

    // 所有失败的数据源
    public Set<String> getFailDataSources() {
        return failDataSources;
    }
}
